import yaml

from config import setting


def read_yaml(key):
    with open(file=setting.extruct_name,encoding="utf-8") as f:
        value = yaml.safe_load(f)
        return value[key]

def read_all_yaml():
    with open(file=setting.extruct_name,encoding="utf-8") as f:
        value = yaml.safe_load(f)
        return value

def write_yaml(data):
    with open(file=setting.extruct_name,mode="a+",encoding="utf-8") as f:
        yaml.safe_dump(data,f,allow_unicode=True)

def clear_yaml():
    with open(file=setting.extruct_name,mode="w",encoding="utf-8"):
        pass

def read_testcase(yaml_path):
    with open(yaml_path,encoding="gbk") as f:
        value = yaml.safe_load(f)
        return value